Page({
  data: {
    dialogVisible: false,
    houseList:[]
  },
 onLoad(){
  this.getHouseList()
 },
 async getHouseList(){
  let houseList=await wx.http.get('/room')
  // console.log(houseList)
  this.setData({houseList})
 },
 //  滑块
  swipeClose(ev) {
    // console.log(ev)
    // 将id挂在全局this上
    this.cellID=ev.mark.id
    const { position, instance } = ev.detail
    if (position === 'right') {
      // 显示 Dialog 对话框
      this.setData({
        dialogVisible: true,
      })
      // swiper-cell 滑块关闭
      instance.close()
    }
  },
// 跳转详情
  goDetail({mark}) {
    // console.log(mark)
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id='+mark.id,
    })
  },
// 新增房屋
  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
  // 弹框组件
  async dialogClose(event){
    // console.log(event)
    if(!event.detail==="confirm") return
    // console.log(111111)
    await wx.http.delete('/room/'+this.cellID)
    wx.utils.toast('删除成功')
    this.getHouseList()
  }
})
